package io.github.cubelitblade.librarymanagementbackend.vo;

import io.github.cubelitblade.librarymanagementbackend.entity.FavoriteRecord;
import io.github.cubelitblade.librarymanagementbackend.entity.FavoriteRecordView;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class FavoriteResponseVO {
    private Integer id;
    private Integer userId;
    private BookBriefVO book;
    private LocalDate createTime;

    /**
     * 将收藏记录和图书简要信息封装为收藏响应视图对象。
     *
     * @param favoriteRecord 收藏记录实体。
     * @param bookBriefVO    图书简要信息视图对象。
     * @return 封装后的收藏响应视图对象。
     */
    public static FavoriteResponseVO of(FavoriteRecord favoriteRecord, BookBriefVO bookBriefVO) {
        return new FavoriteResponseVO(
                favoriteRecord.getId(),
                favoriteRecord.getUserId(),
                bookBriefVO,
                favoriteRecord.getCreateTime()
        );
    }

    /**
     * 将收藏记录视图对象封装为收藏响应视图对象。
     *
     * @param favoriteRecordView 收藏记录视图实体。
     * @return 封装后的收藏响应视图对象。
     */
    public static FavoriteResponseVO of(FavoriteRecordView favoriteRecordView) {
        return new FavoriteResponseVO(
                favoriteRecordView.getId(),
                favoriteRecordView.getUserId(),
                new BookBriefVO(
                        favoriteRecordView.getBookId(),
                        favoriteRecordView.getBookTitle(),
                        favoriteRecordView.getBookAuthor(),
                        favoriteRecordView.getBookStock(),
                        favoriteRecordView.getBookImg()
                ),
                favoriteRecordView.getCreateTime()
        );
    }
}
